namespace Reminder
{
    using System;
    public class ReminderBuilder : IDuration
    {
        const int SEVEN = 7;
        string _name, _message;
        TimeSpan _timeSpan;

        public ReminderBuilder() : this(string.Empty) { }
        public ReminderBuilder(string remindername) : this(remindername, string.Empty) { }
        public ReminderBuilder(string remindername, string remindermessage)
        {
            _name = remindername;
            _message = remindermessage;
        }

        public Reminder Build(bool throwExceptionIfNotValid = false)
        {
            bool notValidTimespan = _timeSpan < TimeSpan.Zero;
            if (throwExceptionIfNotValid && notValidTimespan)
                throw new BuildFailureException();

            return notValidTimespan ? Reminder.Empty : new Reminder(_name, _message, _timeSpan);
        }

        public IDurationDaysTime AddWeeks(int weeks)
        {
            AddDays(SEVEN * weeks);
            return this;
        }

        public IDurationHoursMinutesSeconds AddDays(int days)
        {
            _timeSpan += TimeSpan.FromDays(days);
            return this;
        }

        public IDurationMinutesSeconds AddHours(int hours)
        {
            _timeSpan += TimeSpan.FromHours(hours);
            return this;
        }

        public IDurationSeconds AddMinutes(int minutes)
        {
            _timeSpan += TimeSpan.FromMinutes(minutes);
            return this;
        }

        public IBuild AddSeconds(int seconds)
        {
            _timeSpan += TimeSpan.FromSeconds(seconds);
            return this;
        }
    }
}
